<?
include "include/init.php";

$action = strtolower($_GET["action"]);

MainMenu($smarty);

if($action=="show")
{

	$tempDal = new dal_acl_member();
	$smarty->assign("acl_member_list",$tempDal->get_all());
	$smarty->assign("template",SelectTemplate($smarty,"acl_member_list.tpl"));
	$smarty->display("index.tpl");	
}
elseif($action=="add")
{
	$tempDal = new dal_acl_member();
	
	/* Assign an user object to the template */
	$smarty->assign("acl_member",$tempDal);
	$smarty->assign("template",SelectTemplate($smarty,"acl_member_add.tpl"));
	$smarty->display("index.tpl");	
}
elseif($action=="edit")
{
	try {
			$tempDal = new dal_acl_member();
			$smarty->assign("acl_member",$tempDal->get($_GET["i"]));
			$smarty->assign("template",SelectTemplate($smarty,"acl_member_edit.tpl"));
			$smarty->display("index.tpl");
	
	}
	catch (exception $e){ 
			
		echo $e->GetMessage();
		print_r($e->gettrace());
	} 

}
elseif($action=="save")
{
	$tempObj = new obj_acl_member();
	$tempDal = new dal_acl_member();
	
	
	#$tempObj->set_member_id($_POST["COLUMN.NAME"]);
	
	
	$tempObj->set_member_id($_POST["member_id"]);
	
	$tempObj->set_name($_POST["name"]);
	
	$tempObj->set_password($_POST["password"]);
	
	$tempObj->set_status($_POST["status"]);
	
	
	try {
	
		if($tempObj->get_member_id()!="")
		{
			$tempDal->save($tempObj);
		}
		else
		{
			$tempDal->insert($tempObj);
		}
	
	}
	catch (exception $e){ 
		echo $e->GetMessage();
	} 
	
	$smarty->assign("acl_member_list",$tempDal->get_all());
	$smarty->assign("template",SelectTemplate($smarty,"acl_member_list.tpl"));
	$smarty->display("index.tpl");
}
elseif($action=="delete")
{
	$tempDal = new dal_acl_member();
	
	try {
		$tempDal->delete($_GET["i"]);
	
	}
	catch (exception $e){ 	
		echo $e->GetMessage();
	} 
	
	$smarty->assign("acl_member_list",$tempDal->get_all());
	$smarty->assign("template",SelectTemplate($smarty,"acl_member_list.tpl"));
	$smarty->display("index.tpl");
}
?>